#include <iostream>
#include <thread>
#include <future>

int Add(int num1,int num2)
{
    std::cout << "加法!\n";
    std::this_thread::sleep_for(std::chrono::seconds(3));
    return num1 + num2;
}

int main()
{
    std::cout << "--------1------------" << std::endl;
    std::future<int> result = std::async(std::launch::deferred,Add,11,22);
    std::this_thread::sleep_for(std::chrono::seconds(1));
    std::cout << "--------2------------" << std::endl;
    int sum = result.get();//调用get后再去执行函数内部，std::launch::deferred
    //而std::launch::async则不一样，会异步的完成任务
    std::cout << "--------3------------" << std::endl;
    std::cout << sum << std::endl;
    
    return 0;
}